package bairui.international.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lianjing.sh.model.uml.model.status.State_UpDown;

import bairui.international.model.domain.jpa.TB_IndexModule;
import bairui.international.model.domain.jpa.TB_IndexModuleProduct;
import bairui.international.model.domain.jpa.TB_Product;
import bairui.international.model.domain.jpa.id.ID_IndexModuleProduct;
import bairui.international.service.Service_IndexModule;
import bairui.international.service.Service_IndexModuleProduct;

/**
 * 
 * 【(首页模块)TB_IndexModule】服务实现
 *
 * @generated
 * 
 * @see bairui.international.model.domain.jpa.TB_IndexModule 模型
 * @see Service_IndexModule 服务接口
 * @see BService_IndexModuleImpl 服务实现基础
 *
 */
@Service
public class Service_IndexModuleImpl extends BService_IndexModuleImpl implements Service_IndexModule {

	@Autowired private Service_IndexModuleProduct service_IndexModuleProduct;
	
	@Override
	public TB_IndexModule save(TB_IndexModule input) {
		TB_IndexModule bean = super.save(input);
		findAll().forEach(it->{
			if(it != bean){
				it.setPageFlag(false);
			}
		});
		return bean;
	}
	
	@Override
	public void edit(long id, TB_IndexModule input) throws Exception {
		TB_IndexModule bean = updateWithNonNullProperties(id, input);
		findAll().forEach(it->{
			if(it != bean){
				it.setPageFlag(false);
			}
		});		
	}
	
	@Override
	public void up(long id) throws Exception {
		TB_IndexModule bean = findById(id);
		bean.new UpdateProperties() {
			@Override public State_UpDown getState(TB_IndexModule it) throws Exception {
				return it.getState().t_up_from_Downed().to();
			}
		};
	}

	@Override
	public void publish(long id) throws Exception {
		TB_IndexModule bean = findById(id);
		bean.new UpdateProperties() {
			@Override public State_UpDown getState(TB_IndexModule it) throws Exception {
				return it.getState().t_publish_from_Draft().to();
			}
		};		
	}

	@Override
	public void down(long id) throws Exception {
		TB_IndexModule bean = findById(id);
		bean.new UpdateProperties() {
			@Override public State_UpDown getState(TB_IndexModule it) throws Exception {
				return it.getState().t_down_from_Uped().to();
			}
		};		
	}

	@Override
	public void addProduct(long id, TB_Product product) {
		service_IndexModuleProduct.save(new TB_IndexModuleProduct(
				new TB_IndexModuleProduct.MustProperties() {
					@Override public State_UpDown getState() {
						return State_UpDown.t_create().to();
					}
					
					@Override public ID_IndexModuleProduct getId() {
						return new ID_IndexModuleProduct(product, new TB_IndexModule(id));
					}
				},
				new TB_IndexModuleProduct.OptionalSingleProperties() {
					@Override public String getComment() {
						return null;
					}
				}
			));
	}

}
